home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume2 / pbm / Part4 < prev    next >
Encoding:
Internet Message Format  |  1991-08-07  |  38.9 KB

  1. From: jef@webster.UUCP (Jef Poskanzer)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i082: pbm - Portable Bitmap programs, Part 4/4
  4. Message-ID: <8803292002.AA24567@webster.sybase.uucp>
  5. Date: 29 Mar 88 20:02:59 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. comp.sources.misc: Volume 2, Issue 82
  9. Submitted-By: "Jef Poskanzer" <jef@webster.UUCP>
  10. Archive-Name: pbm/Part4
  11.  
  12. #! /bin/sh
  13. # This is a shell archive, meaning:
  14. # 1. Remove everything above the #! /bin/sh line.
  15. # 2. Save the resulting text in a file.
  16. # 3. Execute the file with /bin/sh (not csh) to create the files:
  17. #    pbmcrop.c
  18. #    pbmcrop.man
  19. #    pbmtrnspos.c
  20. #    pbmtrnspos.man
  21. #    pbmcut.c
  22. #    pbmcut.man
  23. #    pbmpaste.c
  24. #    pbmpaste.man
  25. #    xxxtopbm.c
  26. #    xxxtopbm.man
  27. #    pbmenlarge.c
  28. #    pbmenlarge.man
  29. #    pbmmake.c
  30. #    pbmmake.man
  31. #    libpbm.c
  32. #    pbm.h
  33. #    pbm.man
  34. #    bmaliases
  35. #    bit_reverse.h
  36. # This archive created: Mon Mar 28 12:12:11 1988
  37. # By:    Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal)
  38. export PATH; PATH=/bin:$PATH
  39. echo shar: extracting "'pbmcrop.c'" '(2955 characters)'
  40. if test -f 'pbmcrop.c'
  41. then
  42.     echo shar: will not over-write existing file "'pbmcrop.c'"
  43. else
  44. sed 's/^X//' << \SHAR_EOF > 'pbmcrop.c'
  45. X/* pbmcrop.c - crop a portable bitmap
  46. X**
  47. X** Copyright (C) 1988 by Jef Poskanzer.
  48. X**
  49. X** Permission to use, copy, modify, and distribute this software and its
  50. X** documentation for any purpose and without fee is hereby granted, provided
  51. X** that the above copyright notice appear in all copies and that both that
  52. X** copyright notice and this permission notice appear in supporting
  53. X** documentation.  This software is provided "as is" without express or
  54. X** implied warranty.
  55. X*/
  56. X
  57. X#include <stdio.h>
  58. X#include "pbm.h"
  59. X
  60. Xmain( argc, argv )
  61. Xint argc;
  62. Xchar *argv[];
  63. X    {
  64. X    FILE *ifd;
  65. X    bit **bits, **newbits, background;
  66. X    int argn, backdefault, c;
  67. X    int rows, cols, row, col, newrows, newcols;
  68. X    int top, bottom, left, right;
  69. X    char *usage = "usage:  %s [-0] [-1] [pbmfile]\n";
  70. X
  71. X    argn = 1;
  72. X    backdefault = 1;
  73. X
  74. X    /* Check for flags. */
  75. X    if ( argc > argn )
  76. X    {
  77. X    if ( argv[argn][0] == '-' )
  78. X        {
  79. X        if ( strcmp( argv[argn], "-0" ) == 0 )
  80. X        {
  81. X        backdefault = 0;
  82. X        background = 0;
  83. X        argn++;
  84. X        }
  85. X        else if ( strcmp( argv[argn], "-1" ) == 0 )
  86. X        {
  87. X        backdefault = 0;
  88. X        background = 1;
  89. X        argn++;
  90. X        }
  91. X        else
  92. X        {
  93. X        fprintf( stderr, usage, argv[0] );
  94. X        exit( 1 );
  95. X        }
  96. X        }
  97. X    }
  98. X
  99. X    if ( argc > argn + 1 )
  100. X    {
  101. X    fprintf( stderr, usage, argv[0] );
  102. X    exit( 1 );
  103. X    }
  104. X
  105. X    if ( argc == argn + 1 )
  106. X    {
  107. X        ifd = fopen( argv[argn], "r" );
  108. X        if ( ifd == NULL )
  109. X        {
  110. X        fprintf( stderr, "%s: can't open.\n", argv[argn] );
  111. X        exit( 1 );
  112. X        }
  113. X    }
  114. X    else
  115. X    ifd = stdin;
  116. X
  117. X    bits = pbm_readpbm( ifd, &cols, &rows );
  118. X
  119. X    if ( ifd != stdin )
  120. X    fclose( ifd );
  121. X
  122. X    if ( backdefault )
  123. X    {
  124. X    /* Make a reasonable guess as to what the background is. */
  125. X    c = (int) bits[0][0] + (int) bits[0][cols-1] +
  126. X        (int) bits[rows-1][0] + (int) bits[rows-1][cols-1];
  127. X    background = ( c <= 2 ) ? 0 : 1;
  128. X    }
  129. X
  130. X    /* Find first non-background line. */
  131. X    for ( top = 0; top < rows; top++ )
  132. X    for ( col = 0; col < cols; col++ )
  133. X        if ( bits[top][col] != background )
  134. X        goto gottop;
  135. Xgottop:
  136. X
  137. X    /* Find last non-background line. */
  138. X    for ( bottom = rows-1; bottom >= top; bottom-- )
  139. X    for ( col = 0; col < cols; col++ )
  140. X        if ( bits[bottom][col] != background )
  141. X        goto gotbottom;
  142. Xgotbottom:
  143. X
  144. X    /* Find first non-background column. */
  145. X    for ( left = 0; left < cols; left++ )
  146. X    for ( row = top; row < bottom; row++ )
  147. X        if ( bits[row][left] != background )
  148. X        goto gotleft;
  149. Xgotleft:
  150. X
  151. X    /* Find last non-background column. */
  152. X    for ( right = cols-1; right > left; right-- )
  153. X    for ( row = top; row <= bottom; row++ )
  154. X        if ( bits[row][right] != background )
  155. X        goto gotright;
  156. Xgotright:
  157. X
  158. X    /* Now copy into a new array. */
  159. X    newcols = right - left + 1;
  160. X    newrows = bottom - top + 1;
  161. X    newbits = pbm_allocarray( newcols, newrows );
  162. X    for ( row = top; row <= bottom; row++ )
  163. X        for ( col = left; col <= right; col++ )
  164. X        newbits[row-top][col-left] = bits[row][col];
  165. X
  166. X    pbm_writepbm( stdout, newbits, newcols, newrows );
  167. X
  168. X    exit( 0 );
  169. X    }
  170. SHAR_EOF
  171. if test 2955 -ne "`wc -c < 'pbmcrop.c'`"
  172. then
  173.     echo shar: error transmitting "'pbmcrop.c'" '(should have been 2955 characters)'
  174. fi
  175. fi # end of overwriting check
  176. echo shar: extracting "'pbmcrop.man'" '(1124 characters)'
  177. if test -f 'pbmcrop.man'
  178. then
  179.     echo shar: will not over-write existing file "'pbmcrop.man'"
  180. else
  181. sed 's/^X//' << \SHAR_EOF > 'pbmcrop.man'
  182. X.TH pbmcrop 1 "13 February 1988"
  183. X.SH NAME
  184. Xpbmcrop - crop a portable bitmap
  185. X.SH SYNOPSIS
  186. Xpbmcrop [-0] [-1] [pbmfile]
  187. X.SH DESCRIPTION
  188. XReads a portable bitmap as input.
  189. XRemoves edges that are the background color,
  190. Xand produces a portable bitmap as output.
  191. XBy default, it makes a guess as to what the background
  192. Xcolor is.
  193. XYou can override the default with the -0 and -1 flags.
  194. X.SH "SEE ALSO"
  195. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  196. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  197. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  198. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmtrnspos(1), pbmcut(1),
  199. Xpbmpaste(1), pbmenlarge(1)
  200. X.SH AUTHOR
  201. XCopyright (C) 1988 by Jef Poskanzer.
  202. X
  203. XPermission to use, copy, modify, and distribute this software and its
  204. Xdocumentation for any purpose and without fee is hereby granted, provided
  205. Xthat the above copyright notice appear in all copies and that both that
  206. Xcopyright notice and this permission notice appear in supporting
  207. Xdocumentation.  This software is provided "as is" without express or
  208. Ximplied warranty.
  209. SHAR_EOF
  210. if test 1124 -ne "`wc -c < 'pbmcrop.man'`"
  211. then
  212.     echo shar: error transmitting "'pbmcrop.man'" '(should have been 1124 characters)'
  213. fi
  214. fi # end of overwriting check
  215. echo shar: extracting "'pbmtrnspos.c'" '(1332 characters)'
  216. if test -f 'pbmtrnspos.c'
  217. then
  218.     echo shar: will not over-write existing file "'pbmtrnspos.c'"
  219. else
  220. sed 's/^X//' << \SHAR_EOF > 'pbmtrnspos.c'
  221. X/* pbmtrnspos.c - read a portable bitmap and transpose it x for y
  222. X**
  223. X** Copyright (C) 1988 by Jef Poskanzer.
  224. X**
  225. X** Permission to use, copy, modify, and distribute this software and its
  226. X** documentation for any purpose and without fee is hereby granted, provided
  227. X** that the above copyright notice appear in all copies and that both that
  228. X** copyright notice and this permission notice appear in supporting
  229. X** documentation.  This software is provided "as is" without express or
  230. X** implied warranty.
  231. X*/
  232. X
  233. X#include <stdio.h>
  234. X#include "pbm.h"
  235. X
  236. Xmain( argc, argv )
  237. Xint argc;
  238. Xchar *argv[];
  239. X    {
  240. X    FILE *ifd;
  241. X    bit **bits, **newbits;
  242. X    int rows, cols, row, col;
  243. X
  244. X    if ( argc > 2 )
  245. X    {
  246. X    fprintf( stderr, "usage:  %s [pbmfile]\n", argv[0] );
  247. X    exit( 1 );
  248. X    }
  249. X
  250. X    if ( argc == 2 )
  251. X    {
  252. X        ifd = fopen( argv[1], "r" );
  253. X        if ( ifd == NULL )
  254. X        {
  255. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  256. X        exit( 1 );
  257. X        }
  258. X    }
  259. X    else
  260. X    ifd = stdin;
  261. X
  262. X    bits = pbm_readpbm( ifd, &cols, &rows );
  263. X
  264. X    if ( ifd != stdin )
  265. X    fclose( ifd );
  266. X
  267. X    newbits = pbm_allocarray( rows, cols );    /* note parameter reversal */
  268. X
  269. X    for ( row = 0; row < rows; row++ )
  270. X        for ( col = 0; col < cols; col++ )
  271. X        newbits[col][row] = bits[row][col];
  272. X
  273. X    pbm_writepbm( stdout, newbits, rows, cols );    /* reversed again */
  274. X
  275. X    exit( 0 );
  276. X    }
  277. SHAR_EOF
  278. if test 1332 -ne "`wc -c < 'pbmtrnspos.c'`"
  279. then
  280.     echo shar: error transmitting "'pbmtrnspos.c'" '(should have been 1332 characters)'
  281. fi
  282. fi # end of overwriting check
  283. echo shar: extracting "'pbmtrnspos.man'" '(1318 characters)'
  284. if test -f 'pbmtrnspos.man'
  285. then
  286.     echo shar: will not over-write existing file "'pbmtrnspos.man'"
  287. else
  288. sed 's/^X//' << \SHAR_EOF > 'pbmtrnspos.man'
  289. X.TH pbmtrnspos 1 "18 February 1988"
  290. X.SH NAME
  291. Xpbmtrnspos - transpose a portable bitmap x for y
  292. X.SH SYNOPSIS
  293. Xpbmtrnspos [pbmfile]
  294. X.SH DESCRIPTION
  295. XReads a portable bitmap as input.
  296. XTransposes it x for y and produces a portable bitmap as output.
  297. X.PP
  298. XNote that transposition is not rotation, but can be used to produce it.
  299. XFor example, if you wanted a 90 degree clockwise rotation, perhaps for
  300. Xprinting a landscape bitmap on a laser printer, you could
  301. Xdo 'pbmtrnspos | pbmfliplr' or 'pbmfliptb | pbmtrnspos'.
  302. XFor counter-clockwise rotation, you would use the opposite flips.
  303. X.SH "SEE ALSO"
  304. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  305. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  306. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  307. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmcut(1),
  308. Xpbmpaste(1), pbmenlarge(1)
  309. X.SH AUTHOR
  310. XCopyright (C) 1988 by Jef Poskanzer.
  311. X
  312. XPermission to use, copy, modify, and distribute this software and its
  313. Xdocumentation for any purpose and without fee is hereby granted, provided
  314. Xthat the above copyright notice appear in all copies and that both that
  315. Xcopyright notice and this permission notice appear in supporting
  316. Xdocumentation.  This software is provided "as is" without express or
  317. Ximplied warranty.
  318. SHAR_EOF
  319. if test 1318 -ne "`wc -c < 'pbmtrnspos.man'`"
  320. then
  321.     echo shar: error transmitting "'pbmtrnspos.man'" '(should have been 1318 characters)'
  322. fi
  323. fi # end of overwriting check
  324. echo shar: extracting "'pbmcut.c'" '(2606 characters)'
  325. if test -f 'pbmcut.c'
  326. then
  327.     echo shar: will not over-write existing file "'pbmcut.c'"
  328. else
  329. sed 's/^X//' << \SHAR_EOF > 'pbmcut.c'
  330. X/* pbmcut.c - cut a rectangle out of a portable bitmap
  331. X**
  332. X** Copyright (C) 1988 by Jef Poskanzer.
  333. X**
  334. X** Permission to use, copy, modify, and distribute this software and its
  335. X** documentation for any purpose and without fee is hereby granted, provided
  336. X** that the above copyright notice appear in all copies and that both that
  337. X** copyright notice and this permission notice appear in supporting
  338. X** documentation.  This software is provided "as is" without express or
  339. X** implied warranty.
  340. X*/
  341. X
  342. X#include <stdio.h>
  343. X#include "pbm.h"
  344. X
  345. Xmain( argc, argv )
  346. Xint argc;
  347. Xchar *argv[];
  348. X    {
  349. X    FILE *ifd;
  350. X    bit **bits, **newbits;
  351. X    int rows, cols, x, y, width, height, row, col;
  352. X    char *usage = "usage:  %s x y width height [pbmfile]\n";
  353. X
  354. X
  355. X    if ( argc < 5 || argc > 6 )
  356. X    {
  357. X    fprintf( stderr, usage, argv[0] );
  358. X    exit( 1 );
  359. X    }
  360. X
  361. X    if ( sscanf( argv[1], "%d", &x ) != 1 )
  362. X    {
  363. X    fprintf( stderr, usage, argv[0] );
  364. X    exit( 1 );
  365. X    }
  366. X    if ( sscanf( argv[2], "%d", &y ) != 1 )
  367. X    {
  368. X    fprintf( stderr, usage, argv[0] );
  369. X    exit( 1 );
  370. X    }
  371. X    if ( sscanf( argv[3], "%d", &width ) != 1 )
  372. X    {
  373. X    fprintf( stderr, usage, argv[0] );
  374. X    exit( 1 );
  375. X    }
  376. X    if ( sscanf( argv[4], "%d", &height ) != 1 )
  377. X    {
  378. X    fprintf( stderr, usage, argv[0] );
  379. X    exit( 1 );
  380. X    }
  381. X
  382. X    if ( x < 0 )
  383. X    {
  384. X    fprintf( stderr, "x is less than 0\n" );
  385. X    exit( 1 );
  386. X    }
  387. X    if ( y < 0 )
  388. X    {
  389. X    fprintf( stderr, "y is less than 0\n" );
  390. X    exit( 1 );
  391. X    }
  392. X    if ( width < 1 )
  393. X    {
  394. X    fprintf( stderr, "width is less than 1\n" );
  395. X    exit( 1 );
  396. X    }
  397. X    if ( height < 1 )
  398. X    {
  399. X    fprintf( stderr, "height is less than 1\n" );
  400. X    exit( 1 );
  401. X    }
  402. X
  403. X    if ( argc == 6 )
  404. X    {
  405. X        ifd = fopen( argv[5], "r" );
  406. X        if ( ifd == NULL )
  407. X        {
  408. X        fprintf( stderr, "%s: can't open.\n", argv[5] );
  409. X        exit( 1 );
  410. X        }
  411. X    }
  412. X    else
  413. X    ifd = stdin;
  414. X
  415. X    bits = pbm_readpbm( ifd, &cols, &rows );
  416. X
  417. X    if ( ifd != stdin )
  418. X    fclose( ifd );
  419. X
  420. X    if ( x >= cols )
  421. X    {
  422. X    fprintf(
  423. X        stderr, "x is too large -- the bitmap has only %d cols\n", cols );
  424. X    exit( 1 );
  425. X    }
  426. X    if ( y >= rows )
  427. X    {
  428. X    fprintf(
  429. X        stderr, "y is too large -- the bitmap has only %d rows\n", rows );
  430. X    exit( 1 );
  431. X    }
  432. X    if ( x + width > cols )
  433. X    {
  434. X    fprintf(
  435. X        stderr, "x + width is too large by %d pixels\n", x + width - cols );
  436. X    exit( 1 );
  437. X    }
  438. X    if ( y + height > rows )
  439. X    {
  440. X    fprintf(
  441. X        stderr, "y + height is too large by %d pixels\n",
  442. X        y + height - rows );
  443. X    exit( 1 );
  444. X    }
  445. X
  446. X    newbits = pbm_allocarray( width, height );
  447. X    for ( row = y; row < y + height; row++ )
  448. X        for ( col = x; col < x + width; col++ )
  449. X        newbits[row-y][col-x] = bits[row][col];
  450. X
  451. X    pbm_writepbm( stdout, newbits, width, height );
  452. X
  453. X    exit( 0 );
  454. X    }
  455. SHAR_EOF
  456. if test 2606 -ne "`wc -c < 'pbmcut.c'`"
  457. then
  458.     echo shar: error transmitting "'pbmcut.c'" '(should have been 2606 characters)'
  459. fi
  460. fi # end of overwriting check
  461. echo shar: extracting "'pbmcut.man'" '(1016 characters)'
  462. if test -f 'pbmcut.man'
  463. then
  464.     echo shar: will not over-write existing file "'pbmcut.man'"
  465. else
  466. sed 's/^X//' << \SHAR_EOF > 'pbmcut.man'
  467. X.TH pbmcut 1 "19 February 1988"
  468. X.SH NAME
  469. Xpbmcut - cut a rectangle out of a portable bitmap
  470. X.SH SYNOPSIS
  471. Xpbmcut x y width height [pbmfile]
  472. X.SH DESCRIPTION
  473. XReads a portable bitmap as input.
  474. XExtracts the specified rectangle,
  475. Xand produces a portable bitmap as output.
  476. X.SH "SEE ALSO"
  477. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  478. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  479. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  480. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1),
  481. Xpbmpaste(1), pbmenlarge(1)
  482. X.SH AUTHOR
  483. XCopyright (C) 1988 by Jef Poskanzer.
  484. X
  485. XPermission to use, copy, modify, and distribute this software and its
  486. Xdocumentation for any purpose and without fee is hereby granted, provided
  487. Xthat the above copyright notice appear in all copies and that both that
  488. Xcopyright notice and this permission notice appear in supporting
  489. Xdocumentation.  This software is provided "as is" without express or
  490. Ximplied warranty.
  491. SHAR_EOF
  492. if test 1016 -ne "`wc -c < 'pbmcut.man'`"
  493. then
  494.     echo shar: error transmitting "'pbmcut.man'" '(should have been 1016 characters)'
  495. fi
  496. fi # end of overwriting check
  497. echo shar: extracting "'pbmpaste.c'" '(2402 characters)'
  498. if test -f 'pbmpaste.c'
  499. then
  500.     echo shar: will not over-write existing file "'pbmpaste.c'"
  501. else
  502. sed 's/^X//' << \SHAR_EOF > 'pbmpaste.c'
  503. X/* pbmpaste.c - paste a rectangle into a portable bitmap
  504. X**
  505. X** Copyright (C) 1988 by Jef Poskanzer.
  506. X**
  507. X** Permission to use, copy, modify, and distribute this software and its
  508. X** documentation for any purpose and without fee is hereby granted, provided
  509. X** that the above copyright notice appear in all copies and that both that
  510. X** copyright notice and this permission notice appear in supporting
  511. X** documentation.  This software is provided "as is" without express or
  512. X** implied warranty.
  513. X*/
  514. X
  515. X#include <stdio.h>
  516. X#include "pbm.h"
  517. X
  518. Xmain( argc, argv )
  519. Xint argc;
  520. Xchar *argv[];
  521. X    {
  522. X    FILE *ifd;
  523. X    bit **bits1, **bits2;
  524. X    int rows1, cols1, x, y, rows2, cols2, row, col;
  525. X    char *usage = "usage:  %s frompbmfile x y [intopbmfile]\n";
  526. X
  527. X
  528. X    if ( argc < 4 || argc > 5 )
  529. X    {
  530. X    fprintf( stderr, usage, argv[0] );
  531. X    exit( 1 );
  532. X    }
  533. X
  534. X    ifd = fopen( argv[1], "r" );
  535. X    if ( ifd == NULL )
  536. X    {
  537. X    fprintf( stderr, "%s: can't open.\n", argv[1] );
  538. X    exit( 1 );
  539. X    }
  540. X    bits1 = pbm_readpbm( ifd, &cols1, &rows1 );
  541. X    fclose( ifd );
  542. X
  543. X    if ( sscanf( argv[2], "%d", &x ) != 1 )
  544. X    {
  545. X    fprintf( stderr, usage, argv[0] );
  546. X    exit( 1 );
  547. X    }
  548. X    if ( sscanf( argv[3], "%d", &y ) != 1 )
  549. X    {
  550. X    fprintf( stderr, usage, argv[0] );
  551. X    exit( 1 );
  552. X    }
  553. X
  554. X    if ( x < 0 )
  555. X    {
  556. X    fprintf( stderr, "x is less than 0\n" );
  557. X    exit( 1 );
  558. X    }
  559. X    if ( y < 0 )
  560. X    {
  561. X    fprintf( stderr, "y is less than 0\n" );
  562. X    exit( 1 );
  563. X    }
  564. X
  565. X    if ( argc == 5 )
  566. X    {
  567. X        ifd = fopen( argv[4], "r" );
  568. X        if ( ifd == NULL )
  569. X        {
  570. X        fprintf( stderr, "%s: can't open.\n", argv[4] );
  571. X        exit( 1 );
  572. X        }
  573. X    }
  574. X    else
  575. X    ifd = stdin;
  576. X    bits2 = pbm_readpbm( ifd, &cols2, &rows2 );
  577. X    if ( ifd != stdin )
  578. X    fclose( ifd );
  579. X
  580. X    if ( x >= cols2 )
  581. X    {
  582. X    fprintf(
  583. X        stderr, "x is too large -- the second bitmap has only %d cols\n",
  584. X        cols2 );
  585. X    exit( 1 );
  586. X    }
  587. X    if ( y >= rows2 )
  588. X    {
  589. X    fprintf(
  590. X        stderr, "y is too large -- the second bitmap has only %d rows\n",
  591. X        rows2 );
  592. X    exit( 1 );
  593. X    }
  594. X    if ( x + cols1 > cols2 )
  595. X    {
  596. X    fprintf(
  597. X        stderr, "x + width is too large by %d pixels\n",
  598. X        x + cols1 - cols2 );
  599. X    exit( 1 );
  600. X    }
  601. X    if ( y + rows1 > rows2 )
  602. X    {
  603. X    fprintf(
  604. X        stderr, "y + height is too large by %d pixels\n",
  605. X        y + rows1 - rows2 );
  606. X    exit( 1 );
  607. X    }
  608. X
  609. X    for ( row = 0; row < rows1; row++ )
  610. X        for ( col = 0; col < cols1; col++ )
  611. X        bits2[row+y][col+x] = bits1[row][col];
  612. X
  613. X    pbm_writepbm( stdout, bits2, cols2, rows2 );
  614. X
  615. X    exit( 0 );
  616. X    }
  617. SHAR_EOF
  618. if test 2402 -ne "`wc -c < 'pbmpaste.c'`"
  619. then
  620.     echo shar: error transmitting "'pbmpaste.c'" '(should have been 2402 characters)'
  621. fi
  622. fi # end of overwriting check
  623. echo shar: extracting "'pbmpaste.man'" '(1334 characters)'
  624. if test -f 'pbmpaste.man'
  625. then
  626.     echo shar: will not over-write existing file "'pbmpaste.man'"
  627. else
  628. sed 's/^X//' << \SHAR_EOF > 'pbmpaste.man'
  629. X.TH pbmpaste 1 "19 February 1988"
  630. X.SH NAME
  631. Xpbmpaste - paste a rectangle into a portable bitmap
  632. X.SH SYNOPSIS
  633. Xpbmpaste frompbmfile x y [intopbmfile]
  634. X.SH DESCRIPTION
  635. XReads two portable bitmaps as input.
  636. XInserts the first bitmap into the second at the specified location,
  637. Xand produces a portable bitmap as output.
  638. X.PP
  639. XThis is most useful in combination with pbmcut(1).
  640. XFor instance, if you want to edit a small segment of a large
  641. Xbitmap, and your bitmap editor is TOO STUPID to edit the
  642. Xlarge bitmap, you can cut out the segment you are interested in,
  643. Xedit it, and then paste it back in.
  644. X.SH "SEE ALSO"
  645. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  646. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  647. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  648. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  649. Xpbmenlarge(1)
  650. X.SH AUTHOR
  651. XCopyright (C) 1988 by Jef Poskanzer.
  652. X
  653. XPermission to use, copy, modify, and distribute this software and its
  654. Xdocumentation for any purpose and without fee is hereby granted, provided
  655. Xthat the above copyright notice appear in all copies and that both that
  656. Xcopyright notice and this permission notice appear in supporting
  657. Xdocumentation.  This software is provided "as is" without express or
  658. Ximplied warranty.
  659. SHAR_EOF
  660. if test 1334 -ne "`wc -c < 'pbmpaste.man'`"
  661. then
  662.     echo shar: error transmitting "'pbmpaste.man'" '(should have been 1334 characters)'
  663. fi
  664. fi # end of overwriting check
  665. echo shar: extracting "'xxxtopbm.c'" '(2171 characters)'
  666. if test -f 'xxxtopbm.c'
  667. then
  668.     echo shar: will not over-write existing file "'xxxtopbm.c'"
  669. else
  670. sed 's/^X//' << \SHAR_EOF > 'xxxtopbm.c'
  671. X/* xxxtopbm.c - read an xxx bitmap and write a portable bitmap
  672. X**
  673. X** Copyright (C) 1988 by Jef Poskanzer.
  674. X**
  675. X** Permission to use, copy, modify, and distribute this software and its
  676. X** documentation for any purpose and without fee is hereby granted, provided
  677. X** that the above copyright notice appear in all copies and that both that
  678. X** copyright notice and this permission notice appear in supporting
  679. X** documentation.  This software is provided "as is" without express or
  680. X** implied warranty.
  681. X*/
  682. X
  683. X#include <stdio.h>
  684. X#include "pbm.h"
  685. X
  686. Xmain( argc, argv )
  687. Xint argc;
  688. Xchar *argv[];
  689. X    {
  690. X    FILE *ifd;
  691. X    bit **bits, getbit();
  692. X    int rows, cols, row, col, subcol;
  693. X
  694. X    if ( argc > 2 )
  695. X    {
  696. X    fprintf( stderr, "usage:  %s [xxxfile]\n", argv[0] );
  697. X    exit( 1 );
  698. X    }
  699. X
  700. X    if ( argc == 2 )
  701. X    {
  702. X        ifd = fopen( argv[1], "r" );
  703. X        if ( ifd == NULL )
  704. X        {
  705. X        fprintf( stderr, "%s: can't open.\n", argv[1] );
  706. X        exit( 1 );
  707. X        }
  708. X    }
  709. X    else
  710. X    ifd = stdin;
  711. X
  712. X    getinit( ifd, &cols, &rows );
  713. X
  714. X    bits = pbm_allocarray( cols, rows );
  715. X
  716. X    for ( row = 0; row < rows; row++ )
  717. X        for ( col = 0; col < cols; col += 8 )
  718. X        for ( subcol = col + 7; subcol >= col; subcol-- )
  719. X        bits[row][subcol] = getbit( ifd );
  720. X
  721. X    if ( ifd != stdin )
  722. X    fclose( ifd );
  723. X    
  724. X    pbm_writepbm( stdout, bits, cols, rows );
  725. X
  726. X    exit( 0 );
  727. X    }
  728. X
  729. X
  730. Xint item, bitsperitem, bitshift;
  731. X
  732. Xgetinit( file, colp, rowp )
  733. XFILE *file;
  734. Xint *colp, *rowp;
  735. X    {
  736. X    if ( getc( file ) != 109 )
  737. X    {
  738. X    fprintf( stderr, "Bad magic number 1.\n" );
  739. X    exit( 1 );
  740. X    }
  741. X    if ( getc( file ) != 1 )
  742. X    {
  743. X    fprintf( stderr, "Bad magic number 2.\n" );
  744. X    exit( 1 );
  745. X    }
  746. X    *colp = getc( file );
  747. X    *colp += getc( file ) << 8;
  748. X    *rowp = getc( file );
  749. X    *rowp += getc( file ) << 8;
  750. X    bitsperitem = 8;
  751. X    if ( getc( file ) != 0 )
  752. X    {
  753. X    fprintf( stderr, "Bad magic number 3.\n" );
  754. X    exit( 1 );
  755. X    }
  756. X    if ( getc( file ) != 46 )
  757. X    {
  758. X    fprintf( stderr, "Bad magic number 4.\n" );
  759. X    exit( 1 );
  760. X    }
  761. X    }
  762. X
  763. Xbit
  764. Xgetbit( file )
  765. XFILE *file;
  766. X    {
  767. X    bit b;
  768. X
  769. X    if ( bitsperitem == 8 )
  770. X    {
  771. X    item = getc( file );
  772. X    bitsperitem = 0;
  773. X    bitshift = 7;
  774. X    }
  775. X    bitsperitem++;
  776. X    b = ( item >> bitshift) & 1;
  777. X    bitshift--;
  778. X    return ( b );
  779. X    }
  780. SHAR_EOF
  781. if test 2171 -ne "`wc -c < 'xxxtopbm.c'`"
  782. then
  783.     echo shar: error transmitting "'xxxtopbm.c'" '(should have been 2171 characters)'
  784. fi
  785. fi # end of overwriting check
  786. echo shar: extracting "'xxxtopbm.man'" '(1194 characters)'
  787. if test -f 'xxxtopbm.man'
  788. then
  789.     echo shar: will not over-write existing file "'xxxtopbm.man'"
  790. else
  791. sed 's/^X//' << \SHAR_EOF > 'xxxtopbm.man'
  792. X.TH xxxtopbm 1 "21 February 1988"
  793. X.SH NAME
  794. Xxxxtopbm - convert "xxx" bitmaps into portable bitmaps
  795. X.SH SYNOPSIS
  796. Xxxxtopbm [xxxfile]
  797. X.SH DESCRIPTION
  798. XReads an "xxx" bitmap as input.
  799. XProduces a portable bitmap as output.
  800. X.LP
  801. X"xxx" bitmaps are the unknown and undocumented format found on
  802. Xucbvax.Berkeley.Edu in the directory pub/xbackgrounds.
  803. XThe arrangement of the bits is the same as for Sun rasterfiles, but
  804. Xthe headers are completely different.
  805. X.SH "SEE ALSO"
  806. Xpbm(5), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  807. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  808. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  809. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  810. Xpbmpaste(1), pbmenlarge(1)
  811. X.SH AUTHOR
  812. XCopyright (C) 1988 by Jef Poskanzer.
  813. X
  814. XPermission to use, copy, modify, and distribute this software and its
  815. Xdocumentation for any purpose and without fee is hereby granted, provided
  816. Xthat the above copyright notice appear in all copies and that both that
  817. Xcopyright notice and this permission notice appear in supporting
  818. Xdocumentation.  This software is provided "as is" without express or
  819. Ximplied warranty.
  820. SHAR_EOF
  821. if test 1194 -ne "`wc -c < 'xxxtopbm.man'`"
  822. then
  823.     echo shar: error transmitting "'xxxtopbm.man'" '(should have been 1194 characters)'
  824. fi
  825. fi # end of overwriting check
  826. echo shar: extracting "'pbmenlarge.c'" '(1950 characters)'
  827. if test -f 'pbmenlarge.c'
  828. then
  829.     echo shar: will not over-write existing file "'pbmenlarge.c'"
  830. else
  831. sed 's/^X//' << \SHAR_EOF > 'pbmenlarge.c'
  832. X/* pbmenlarge.c - read a portable bitmap and enlarge it N times
  833. X**
  834. X** Copyright (C) 1988 by Jef Poskanzer.
  835. X**
  836. X** Permission to use, copy, modify, and distribute this software and its
  837. X** documentation for any purpose and without fee is hereby granted, provided
  838. X** that the above copyright notice appear in all copies and that both that
  839. X** copyright notice and this permission notice appear in supporting
  840. X** documentation.  This software is provided "as is" without express or
  841. X** implied warranty.
  842. X*/
  843. X
  844. X#include <stdio.h>
  845. X#include "pbm.h"
  846. X
  847. Xmain( argc, argv )
  848. Xint argc;
  849. Xchar *argv[];
  850. X    {
  851. X    FILE *ifd;
  852. X    bit **bits, **newbits;
  853. X    int argn, n, rows, cols, row, col, subrow, subcol;
  854. X    char *usage = "usage:  %s [-N] [pbmfile]\n";
  855. X
  856. X    if ( argc > 3 )
  857. X    {
  858. X    fprintf( stderr, usage, argv[0] );
  859. X    exit( 1 );
  860. X    }
  861. X
  862. X    n = 0;
  863. X    ifd = stdin;
  864. X
  865. X    for ( argn = 1; argn < argc; argn++ )
  866. X    {
  867. X    if ( argv[argn][0] == '-' )
  868. X        {
  869. X        if ( n != 0 )
  870. X        {
  871. X        fprintf( stderr, usage, argv[0] );
  872. X        exit( 1 );
  873. X        }
  874. X        if ( sscanf( &(argv[argn][1]), "%d", &n ) != 1 )
  875. X        {
  876. X        fprintf( stderr, usage, argv[0] );
  877. X        exit( 1 );
  878. X        }
  879. X        if ( n < 2 )
  880. X        {
  881. X        fprintf( stderr, usage, argv[0] );
  882. X        exit( 1 );
  883. X        }
  884. X        }
  885. X    else
  886. X        {
  887. X        if ( ifd != stdin )
  888. X        {
  889. X        fprintf( stderr, usage, argv[0] );
  890. X        exit( 1 );
  891. X        }
  892. X        ifd = fopen( argv[argn], "r" );
  893. X        if ( ifd == NULL )
  894. X        {
  895. X        fprintf( stderr, "%s: can't open.\n", argv[argn] );
  896. X        exit( 1 );
  897. X        }
  898. X        }
  899. X    }
  900. X    
  901. X    if ( n == 0 )
  902. X    n = 2;    /* default to double */
  903. X
  904. X    bits = pbm_readpbm( ifd, &cols, &rows );
  905. X
  906. X    if ( ifd != stdin )
  907. X    fclose( ifd );
  908. X
  909. X    newbits = pbm_allocarray( cols * n, rows * n );
  910. X
  911. X    for ( row = 0; row < rows; row++ )
  912. X        for ( col = 0; col < cols; col++ )
  913. X        for ( subrow = 0; subrow < n; subrow++ )
  914. X        for ( subcol = 0; subcol < n; subcol++ )
  915. X            newbits[row * n + subrow][col * n + subcol] =
  916. X            bits[row][col];
  917. X
  918. X    pbm_writepbm( stdout, newbits, cols * n, rows * n );
  919. X
  920. X    exit( 0 );
  921. X    }
  922. SHAR_EOF
  923. if test 1950 -ne "`wc -c < 'pbmenlarge.c'`"
  924. then
  925.     echo shar: error transmitting "'pbmenlarge.c'" '(should have been 1950 characters)'
  926. fi
  927. fi # end of overwriting check
  928. echo shar: extracting "'pbmenlarge.man'" '(1044 characters)'
  929. if test -f 'pbmenlarge.man'
  930. then
  931.     echo shar: will not over-write existing file "'pbmenlarge.man'"
  932. else
  933. sed 's/^X//' << \SHAR_EOF > 'pbmenlarge.man'
  934. X.TH pbmenlarge 1 "29 February 1988"
  935. X.SH NAME
  936. Xpbmenlarge - read a portable bitmap and enlarge it N times
  937. X.SH SYNOPSIS
  938. Xpbmenlarge [-N] [pbmfile]
  939. X.SH DESCRIPTION
  940. XReads a portable bitmap as input.
  941. XReplicates its bits N times, and produces a portable bitmap as output.
  942. XThe default enlargement is two.
  943. X.SH "SEE ALSO"
  944. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  945. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  946. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  947. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  948. Xpbmpaste(1)
  949. X.SH AUTHOR
  950. XCopyright (C) 1988 by Jef Poskanzer.
  951. X
  952. XPermission to use, copy, modify, and distribute this software and its
  953. Xdocumentation for any purpose and without fee is hereby granted, provided
  954. Xthat the above copyright notice appear in all copies and that both that
  955. Xcopyright notice and this permission notice appear in supporting
  956. Xdocumentation.  This software is provided "as is" without express or
  957. Ximplied warranty.
  958. SHAR_EOF
  959. if test 1044 -ne "`wc -c < 'pbmenlarge.man'`"
  960. then
  961.     echo shar: error transmitting "'pbmenlarge.man'" '(should have been 1044 characters)'
  962. fi
  963. fi # end of overwriting check
  964. echo shar: extracting "'pbmmake.c'" '(1174 characters)'
  965. if test -f 'pbmmake.c'
  966. then
  967.     echo shar: will not over-write existing file "'pbmmake.c'"
  968. else
  969. sed 's/^X//' << \SHAR_EOF > 'pbmmake.c'
  970. X/* pbmmake.c - create a blank bitmap of a specified size
  971. X**
  972. X** Copyright (C) 1988 by Jef Poskanzer.
  973. X**
  974. X** Permission to use, copy, modify, and distribute this software and its
  975. X** documentation for any purpose and without fee is hereby granted, provided
  976. X** that the above copyright notice appear in all copies and that both that
  977. X** copyright notice and this permission notice appear in supporting
  978. X** documentation.  This software is provided "as is" without express or
  979. X** implied warranty.
  980. X*/
  981. X
  982. X#include <stdio.h>
  983. X#include "pbm.h"
  984. X
  985. Xmain( argc, argv )
  986. Xint argc;
  987. Xchar *argv[];
  988. X    {
  989. X    bit **bits;
  990. X    int rows, cols, row, col;
  991. X    char *usage = "usage:  %s <width> <height>\n";
  992. X
  993. X    if ( argc != 3 )
  994. X    {
  995. X    fprintf( stderr, usage, argv[0] );
  996. X    exit( 1 );
  997. X    }
  998. X
  999. X    if ( sscanf( argv[1], "%d", &cols ) != 1 )
  1000. X    {
  1001. X    fprintf( stderr, usage, argv[0] );
  1002. X    exit( 1 );
  1003. X    }
  1004. X    if ( sscanf( argv[2], "%d", &rows ) != 1 )
  1005. X    {
  1006. X    fprintf( stderr, usage, argv[0] );
  1007. X    exit( 1 );
  1008. X    }
  1009. X
  1010. X    bits = pbm_allocarray( cols, rows );
  1011. X
  1012. X    for ( row = 0; row < rows; row++ )
  1013. X        for ( col = 0; col < cols; col++ )
  1014. X        bits[row][col] = 0;
  1015. X
  1016. X    pbm_writepbm( stdout, bits, cols, rows );
  1017. X
  1018. X    exit( 0 );
  1019. X    }
  1020. SHAR_EOF
  1021. if test 1174 -ne "`wc -c < 'pbmmake.c'`"
  1022. then
  1023.     echo shar: error transmitting "'pbmmake.c'" '(should have been 1174 characters)'
  1024. fi
  1025. fi # end of overwriting check
  1026. echo shar: extracting "'pbmmake.man'" '(981 characters)'
  1027. if test -f 'pbmmake.man'
  1028. then
  1029.     echo shar: will not over-write existing file "'pbmmake.man'"
  1030. else
  1031. sed 's/^X//' << \SHAR_EOF > 'pbmmake.man'
  1032. X.TH pbmmake 1 "24 March 1988"
  1033. X.SH NAME
  1034. Xpbmmake - create a blank bitmap of a specified size
  1035. X.SH SYNOPSIS
  1036. Xpbmmake <width> <height>
  1037. X.SH DESCRIPTION
  1038. XProduces an all-white portable bitmap of the specified width and height.
  1039. X.SH "SEE ALSO"
  1040. Xpbm(5), cbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  1041. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  1042. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  1043. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  1044. Xpbmpaste(1), pbmenlarge(1)
  1045. X.SH AUTHOR
  1046. XCopyright (C) 1988 by Jef Poskanzer.
  1047. X
  1048. XPermission to use, copy, modify, and distribute this software and its
  1049. Xdocumentation for any purpose and without fee is hereby granted, provided
  1050. Xthat the above copyright notice appear in all copies and that both that
  1051. Xcopyright notice and this permission notice appear in supporting
  1052. Xdocumentation.  This software is provided "as is" without express or
  1053. Ximplied warranty.
  1054. SHAR_EOF
  1055. if test 981 -ne "`wc -c < 'pbmmake.man'`"
  1056. then
  1057.     echo shar: error transmitting "'pbmmake.man'" '(should have been 981 characters)'
  1058. fi
  1059. fi # end of overwriting check
  1060. echo shar: extracting "'libpbm.c'" '(2749 characters)'
  1061. if test -f 'libpbm.c'
  1062. then
  1063.     echo shar: will not over-write existing file "'libpbm.c'"
  1064. else
  1065. sed 's/^X//' << \SHAR_EOF > 'libpbm.c'
  1066. X/* libpbm.c - pbm utility library
  1067. X**
  1068. X** Copyright (C) 1988 by Jef Poskanzer.
  1069. X**
  1070. X** Permission to use, copy, modify, and distribute this software and its
  1071. X** documentation for any purpose and without fee is hereby granted, provided
  1072. X** that the above copyright notice appear in all copies and that both that
  1073. X** copyright notice and this permission notice appear in supporting
  1074. X** documentation.  This software is provided "as is" without express or
  1075. X** implied warranty.
  1076. X*/
  1077. X
  1078. X#include <stdio.h>
  1079. X#include "pbm.h"
  1080. X
  1081. Xint
  1082. Xpbm_getint( file )
  1083. XFILE *file;
  1084. X    {
  1085. X    char ch;
  1086. X    int i;
  1087. X
  1088. X    do
  1089. X    {
  1090. X    ch = pbm_getc( file );
  1091. X    }
  1092. X    while ( ch == ' ' || ch == '\t' || ch == '\n' );
  1093. X
  1094. X    if ( ch < '0' || ch > '9' )
  1095. X    {
  1096. X    fprintf( stderr, "Junk in file where an integer should be!\n" );
  1097. X    exit( 1 );
  1098. X    }
  1099. X
  1100. X    i = 0;
  1101. X    do
  1102. X    {
  1103. X    i = i * 10 + ch - '0';
  1104. X    ch = pbm_getc( file );
  1105. X        }
  1106. X    while ( ch >= '0' && ch <= '9' );
  1107. X
  1108. X    return ( i );
  1109. X    }
  1110. X
  1111. X
  1112. Xbit
  1113. Xpbm_getbit( file )
  1114. XFILE *file;
  1115. X    {
  1116. X    char ch;
  1117. X
  1118. X    do
  1119. X    {
  1120. X    ch = pbm_getc( file );
  1121. X    }
  1122. X    while ( ch == ' ' || ch == '\t' || ch == '\n' );
  1123. X
  1124. X    if ( ch != '0' && ch != '1' )
  1125. X    {
  1126. X    fprintf( stderr, "Junk in file where bits should be!\n" );
  1127. X    exit( 1 );
  1128. X    }
  1129. X
  1130. X    return ( ( ch == '1' ) ? 1 : 0 );
  1131. X    }
  1132. X
  1133. Xchar
  1134. Xpbm_getc( file )
  1135. XFILE *file;
  1136. X    {
  1137. X    int ich;
  1138. X    char ch;
  1139. X
  1140. X    ich = getc( file );
  1141. X    if ( ich == NULL )
  1142. X    {
  1143. X    fprintf( stderr, "Premature EOF.\n" );
  1144. X    exit( 1 );
  1145. X    }
  1146. X    ch = (char) ich;
  1147. X    
  1148. X    if ( ch == '#' )
  1149. X    {
  1150. X    do
  1151. X        {
  1152. X        ich = getc( file );
  1153. X        if ( ich == NULL )
  1154. X        {
  1155. X        fprintf( stderr, "Premature EOF.\n" );
  1156. X        exit( 1 );
  1157. X        }
  1158. X        ch = (char) ich;
  1159. X        }
  1160. X    while ( ch != '\n' );
  1161. X    }
  1162. X
  1163. X    return ( ch );
  1164. X    }
  1165. X
  1166. Xbit **
  1167. Xpbm_allocarray( cols, rows )
  1168. Xint cols, rows;
  1169. X    {
  1170. X    bit **bits;
  1171. X    int i;
  1172. X
  1173. X    bits = (bit **) malloc( rows * sizeof( bit *) );
  1174. X    for ( i = 0; i < rows; i++ )
  1175. X    {
  1176. X    bits[i] = (bit *) malloc( cols * sizeof( bit ) );
  1177. X    }
  1178. X
  1179. X    return ( bits );
  1180. X    }
  1181. X
  1182. X
  1183. Xbit **pbm_readpbm( file, colsP, rowsP )
  1184. XFILE *file;
  1185. Xint *colsP, *rowsP;
  1186. X    {
  1187. X    bit **bits;
  1188. X    int row, col;
  1189. X
  1190. X    *colsP = pbm_getint( file );
  1191. X    *rowsP = pbm_getint( file );
  1192. X
  1193. X    bits = pbm_allocarray( *colsP, *rowsP );
  1194. X
  1195. X    for ( row = 0; row < *rowsP; row++ )
  1196. X        for ( col = 0; col < *colsP; col++ )
  1197. X        bits[row][col] = pbm_getbit( file );
  1198. X
  1199. X    return ( bits );
  1200. X    }
  1201. X
  1202. Xpbm_writepbm( file, bits, cols, rows )
  1203. XFILE *file;
  1204. Xbit **bits;
  1205. Xint cols, rows;
  1206. X    {
  1207. X    int row, col, linecount;
  1208. X
  1209. X    fprintf( file, "%d %d\n", cols, rows );
  1210. X
  1211. X    for ( row = 0; row < rows; row++ )
  1212. X    {
  1213. X    linecount = 0;
  1214. X        for ( col = 0; col < cols; col++ )
  1215. X        {
  1216. X        if ( linecount >= 70 )
  1217. X        {
  1218. X        putc( '\n', file );
  1219. X        linecount = 0;
  1220. X        }
  1221. X        putc( bits[row][col] ? '1' : '0', file );
  1222. X        linecount++;
  1223. X        }
  1224. X    putc( '\n', file );
  1225. X        }
  1226. X    }
  1227. SHAR_EOF
  1228. if test 2749 -ne "`wc -c < 'libpbm.c'`"
  1229. then
  1230.     echo shar: error transmitting "'libpbm.c'" '(should have been 2749 characters)'
  1231. fi
  1232. fi # end of overwriting check
  1233. echo shar: extracting "'pbm.h'" '(490 characters)'
  1234. if test -f 'pbm.h'
  1235. then
  1236.     echo shar: will not over-write existing file "'pbm.h'"
  1237. else
  1238. sed 's/^X//' << \SHAR_EOF > 'pbm.h'
  1239. X/* pbm.h - header file for libpbm portable bitmap library
  1240. X*/
  1241. X
  1242. Xtypedef unsigned char bit;
  1243. X
  1244. X/* Declarations of routines. */
  1245. X
  1246. Xint pbm_getint( );
  1247. X    /* i = pbm_getint( file ); */
  1248. Xbit pbm_getbit( );
  1249. X    /* b = pbm_getbit( file ); */
  1250. Xchar pbm_getc( );
  1251. X    /* c = pbm_getc( file ); */
  1252. Xbit **pbm_allocarray( );
  1253. X    /* bits = pbm_allocarray( cols, rows ); bits[row][col]; */
  1254. Xbit **pbm_readpbm( );
  1255. X    /* bits = pbm_readpbm( file, &cols, &rows ); */
  1256. Xpbm_writepbm( );
  1257. X    /* pbm_writepbm( file, bits, cols, rows ); */
  1258. SHAR_EOF
  1259. if test 490 -ne "`wc -c < 'pbm.h'`"
  1260. then
  1261.     echo shar: error transmitting "'pbm.h'" '(should have been 490 characters)'
  1262. fi
  1263. fi # end of overwriting check
  1264. echo shar: extracting "'pbm.man'" '(2415 characters)'
  1265. if test -f 'pbm.man'
  1266. then
  1267.     echo shar: will not over-write existing file "'pbm.man'"
  1268. else
  1269. sed 's/^X//' << \SHAR_EOF > 'pbm.man'
  1270. X.TH pbm 5 "18 February 1988"
  1271. X.SH NAME
  1272. Xpbm - portable bitmap file format
  1273. X.SH DESCRIPTION
  1274. XThe portable bitmap format is a lowest common denominator.
  1275. XIt was originally designed to make it reasonable to mail bitmaps
  1276. Xbetween different types of machines using the typical stupid network
  1277. Xmailers we have today.
  1278. XNow it serves as the common language of a large family of bitmap
  1279. Xconversion filters.
  1280. XThe definition is as follows:
  1281. X.IP - 2
  1282. XA width, formatted as ASCII characters in decimal.
  1283. X.IP - 2
  1284. XWhitespace (blanks, TABs, CRs, LFs).
  1285. X.IP - 2
  1286. XA height, again in ASCII decimal.
  1287. X.IP - 2
  1288. XWhitespace.
  1289. X.IP - 2
  1290. XWidth * height bits, each either '1' or '0', starting at the top-left
  1291. Xcorner of the bitmap, proceding in normal English reading order.
  1292. X.IP - 2
  1293. XThe character '1' means black, '0' means white.
  1294. X.IP - 2
  1295. XWhitespace in the bits section is ignored.
  1296. X.IP - 2
  1297. XCharacters from a "#" to the next end-of-line are ignored (comments).
  1298. X.IP - 2
  1299. XNo line may be longer than 70 characters.
  1300. X.PP
  1301. XHere is an example of a small bitmap in this format:
  1302. X.PP
  1303. X.nf
  1304. X# feep.pbm
  1305. X24 7
  1306. X0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  1307. X0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
  1308. X0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
  1309. X0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
  1310. X0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
  1311. X0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
  1312. X0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  1313. X.fi
  1314. X.PP
  1315. XPrograms that read this format should be as lenient as possible,
  1316. Xaccepting anything that looks remotely like a bitmap.
  1317. XFor instance, the above example does not actually conform to the
  1318. Xstandard, since it has whitespace before the width; neverthless,
  1319. Xit should be accepted.
  1320. X.SH "SEE ALSO"
  1321. Xcbmtopbm(1), icontopbm(1), macptopbm(1), rasttopbm(1), xbmtopbm(1), xwdtopbm(1),
  1322. Xpbmtoicon(1), pbmtocbm(1), pbmtops(1), pbmtoptx(1), pbmtorast(1),
  1323. Xpbmtoxbm(1), pbmtox10bm(1), pbmtoascii(1), pbminvert(1), pbmfliplr(1),
  1324. Xpbmfliptb(1), pbmcatlr(1), pbmcattb(1), pbmcrop(1), pbmtrnspos(1), pbmcut(1),
  1325. Xpbmpaste(1), pbmenlarge(1)
  1326. X.SH AUTHOR
  1327. XCopyright (C) 1988 by Jef Poskanzer.
  1328. X
  1329. XPermission to use, copy, modify, and distribute this software and its
  1330. Xdocumentation for any purpose and without fee is hereby granted, provided
  1331. Xthat the above copyright notice appear in all copies and that both that
  1332. Xcopyright notice and this permission notice appear in supporting
  1333. Xdocumentation.  This software is provided "as is" without express or
  1334. Ximplied warranty.
  1335. SHAR_EOF
  1336. if test 2415 -ne "`wc -c < 'pbm.man'`"
  1337. then
  1338.     echo shar: error transmitting "'pbm.man'" '(should have been 2415 characters)'
  1339. fi
  1340. fi # end of overwriting check
  1341. echo shar: extracting "'bmaliases'" '(445 characters)'
  1342. if test -f 'bmaliases'
  1343. then
  1344.     echo shar: will not over-write existing file "'bmaliases'"
  1345. else
  1346. sed 's/^X//' << \SHAR_EOF > 'bmaliases'
  1347. X# This script must be sourced - it will not work if you run it in a sub-shell.
  1348. X
  1349. Xset _bmtypes="ascii cbm icon macp ps ptx rast xbm x10bm xwd xxx"
  1350. X
  1351. Xforeach i ( $_bmtypes )
  1352. X    if ( $i != ascii && $i != ps && $i != ptx && $i != x10bm ) then
  1353. X    foreach j ( $_bmtypes )
  1354. X        if ( $j != macp && $j != xwd && $j != xxx ) then
  1355. X        if ( $i != $j ) then
  1356. X            alias ${i}to${j} "( ${i}topbm | pbmto${j} )"
  1357. X        endif
  1358. X        endif
  1359. X    end
  1360. X    endif
  1361. Xend
  1362. X
  1363. Xunset _bmtypes
  1364. SHAR_EOF
  1365. if test 445 -ne "`wc -c < 'bmaliases'`"
  1366. then
  1367.     echo shar: error transmitting "'bmaliases'" '(should have been 445 characters)'
  1368. fi
  1369. fi # end of overwriting check
  1370. echo shar: extracting "'bit_reverse.h'" '(1994 characters)'
  1371. if test -f 'bit_reverse.h'
  1372. then
  1373.     echo shar: will not over-write existing file "'bit_reverse.h'"
  1374. else
  1375. sed 's/^X//' << \SHAR_EOF > 'bit_reverse.h'
  1376. X/*
  1377. X** bit_reverse.h
  1378. X**
  1379. X** This particular array seems to be useful in a lot of bitmap
  1380. X** conversion programs.  It's not used in pbm because bits are
  1381. X** stored one per byte, for easier manipulation.  But if you wanted
  1382. X** to write, for example, a program to directly convert Sun raster
  1383. X** format into X bitmaps, you could use this.
  1384. X*/
  1385. X
  1386. Xunsigned char bit_reverse[256] = {
  1387. X    0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0,
  1388. X    0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
  1389. X    0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4,
  1390. X    0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
  1391. X    0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc,
  1392. X    0x3c, 0xbc, 0x7c, 0xfc, 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
  1393. X    0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, 0x0a, 0x8a, 0x4a, 0xca,
  1394. X    0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
  1395. X    0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6,
  1396. X    0x36, 0xb6, 0x76, 0xf6, 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
  1397. X    0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x01, 0x81, 0x41, 0xc1,
  1398. X    0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
  1399. X    0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9,
  1400. X    0x39, 0xb9, 0x79, 0xf9, 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
  1401. X    0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 0x0d, 0x8d, 0x4d, 0xcd,
  1402. X    0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
  1403. X    0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3,
  1404. X    0x33, 0xb3, 0x73, 0xf3, 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
  1405. X    0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 0x07, 0x87, 0x47, 0xc7,
  1406. X    0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
  1407. X    0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf,
  1408. X    0x3f, 0xbf, 0x7f, 0xff};
  1409. SHAR_EOF
  1410. if test 1994 -ne "`wc -c < 'bit_reverse.h'`"
  1411. then
  1412.     echo shar: error transmitting "'bit_reverse.h'" '(should have been 1994 characters)'
  1413. fi
  1414. fi # end of overwriting check
  1415. #    End of shell archive
  1416. exit 0
  1417.